package com.yanqu.road.server.logic.task.condition;

import com.yanqu.road.entity.enums.eALiActivityChannel;
import com.yanqu.road.entity.enums.eGamePlayerEventType;
import com.yanqu.road.entity.enums.eTaskType;
import com.yanqu.road.entity.task.TaskConditionInfo;
import com.yanqu.road.entity.task.TaskInfo;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.task.TaskModule;
import com.yanqu.road.server.logic.task.BaseCondition;
import com.yanqu.road.server.logic.task.BaseTaskData;
import com.yanqu.road.server.manger.config.TaskMgr;

import java.math.BigInteger;

/**
 * 关卡谈判成功次数
 */
public class PassBattleSuccessTimesCondition extends BaseCondition {

	public PassBattleSuccessTimesCondition(TaskConditionInfo conditionInfo, BaseTaskData quest, BigInteger value, Object initArgs) {
		super(conditionInfo, quest, value, initArgs);
	}

	@Override
	public void addTrigger(GamePlayer player) {
		player.getModule(TaskModule.class).getGameEvent().addListener(eGamePlayerEventType.PassBattleSuccessTimes.getValue(), handle);
	}

	@Override
	public void removeTrigger(GamePlayer player) {
		player.getModule(TaskModule.class).getGameEvent().removeListener(eGamePlayerEventType.PassBattleSuccessTimes.getValue(), handle);
	}

	public boolean isCompleted(GamePlayer player) {
		BigInteger param4 = taskConditionInfo.getParamList().get(3);
		return getValue().compareTo(param4) >= 0;
	}

	@Override
	protected void changeValue(Object object) {
		int taskId = taskConditionInfo.getTaskId();
		TaskInfo taskInfo = TaskMgr.getTaskInfoById(taskId);
		if(taskInfo != null && taskInfo.getType() == eTaskType.ALiPayFiveBlessingsTask.getValue()){
			//瓜分渠道，不达成
			if(eALiActivityChannel.GuanFen.getValue().equals(player.getZfbChannel())){
				return;
			}
		}
		int times = (int) object;
		setValue(getValue().add(BigInteger.valueOf(times)));
	}

}
